import http from '../api/http'

//轮播图
function getBanner(pageNum = 1,pageSize = 10) {
    const url = `/api/cms/article/open/banner/list`;
    const formData = new FormData();
    formData.append("pageNum",pageNum);
    formData.append("pageSize",pageSize);
    return http.post(url,formData)
}

//搜索
function search(title="") {
    const url = `/api/cms/article/open/list?pageNum=1&pageSize=10&title=${title}`;
    return http.post(url)
}

//新闻列表
function getNews(pageNum = 1, pageSize = 12, categoryId) {
    const url = `/api/cms/article/open/list`;
    const formData = new FormData();
    formData.append("pageNum",pageNum);
    formData.append("pageSize",pageSize);
    if (categoryId) {
        formData.append("categoryId", categoryId);
    }
    return http.post(url,formData)
}

//获取新闻详情
function getNewsDetails(articleId = 1645) {
    const url = `/api/cms/article/open/detail/${articleId}`;
    return http.get(url)
}

//栏目分类
function getClassify(pageNum = 1,pageSize = 22) {
    const url = `/api/cms/category/open/list`;
    const formData = new FormData();
    formData.append("pageNum",pageNum);
    formData.append("pageSize",pageSize);
    return http.post(url,formData)
}

//点击收藏
function getCollect(articleId = 11360) {
    const url = `/api/cms/collect/collect/article/${articleId}`;
    return http.get(url)
}

//收藏文章详情
function collectDetails(articleId = 11360) {
    const url = `/api/cms/article/open/detail/${articleId}`;
    return http.get(url)
}

//点赞
function getPraise(articleId = 11360) {
    const url = `/api/cms/article/add/zan/${articleId}`;
    return http.get(url)
}

//阅读量
function addRead(articleId = 11360) {
    const url = `/api/cms/article/open/add/read-num/${articleId}`;
    return http.get(url)
}

//天气
function getWeather(appkey = 'eed9a7a326471393',city = "") {
    const url = `/jisuapi/weather/query?appkey=${appkey}&city=${city}`;
    return http.post(url)
}

//历史上的今天
function historyToday(appkey = 'eed9a7a326471393',month = 1, day = 2) {
    const url = `/jisuapi/todayhistory/query?appkey=${appkey}&month=${month}&day=${day}`;
    return http.get(url)
}

//订阅
function subscription(categoryIds) {
    const url = `/api/cms/userCategory/subscription/category`;
    const formData = new FormData();
    formData.append("categoryIds",categoryIds);
    return http.post(url,formData);
}

//订阅列表
function subscriptionList() {
    const url = `/api/cms/category/subscription/list`;
    return http.get(url)
}

//订阅详情
function subscriptionDetails(pageNum,pageSize,categoryId) {
    const url = `/api/cms/article/open/list`;
    const formData = new FormData();
    formData.append("pageNum",pageNum);
    formData.append("pageSize",pageSize);
    formData.append("categoryId",categoryId);
    return http.post(url,formData);
}

//发布帖子
function sendPost(categoryId,title,intro,coverImgUrl) {
    const url = `/api/bbs/bbsPosts/site/add`;
    const formData = new FormData();
    formData.append("categoryId",categoryId);
    formData.append("title",title);
    formData.append("intro",intro);
    formData.append("coverImgUrl",coverImgUrl);
    return http.post(url,formData);
}

//发布分类
function sendCategory() {
    const url = `/api/bbs/bbsCategory/open/list`;
    return http.post(url);
}

export {
    getBanner,
    search,
    getNews,
    getNewsDetails,
    getClassify,
    getCollect,
    collectDetails,
    getPraise,
    addRead,
    getWeather,
    historyToday,
    subscription,
    subscriptionList,
    subscriptionDetails,
    sendPost,
    sendCategory
}